#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'tian'
__data__ = '2021/3/4 11:30'

from page.loginpage import LoginPage
from conf import settings


class LoginHandle:
    """
    登录页面的逻辑处理
    """

    def __init__(self):
        self.obj_login = LoginPage()
        self.username = settings.COMMON_PARAMETERS.get("admin")
        self.pwd = settings.COMMON_PARAMETERS.get("password")
        self.open_title = "HARBOR PROPERTY MANAGEMENT SYSTEM"
        self.user_ane_pwd_null = "请输入账号"
        self.user_or_pwd_error = "用户名或密码错误"
        self.login_success = "tianx"

    def open_admin_page(self):
        """
        登录页面是否打开正常
        :return: 正常返回True
        """
        result_current_title = self.obj_login.open_admin_page()
        return self.open_title, result_current_title

    def user_and_password_null(self):
        """
        用户名和密码为空
        :return:
        """
        rest_text = self.obj_login.user_and_password_all_null()
        return self.user_ane_pwd_null, rest_text

    def user_and_password_error(self):
        """
        用户名和密码都输入错误
        :return:
        """
        rest_error = self.obj_login.input_username_password_and_username_error('xiangxiang', '123456896%%')
        return self.user_or_pwd_error, rest_error

    def input_error_user_and_correct_password(self):
        """
        输入错误的用户名、正确的密码
        :return:
        """
        rest_error = self.obj_login.input_username_password_and_username_error('tianxiang2009', self.pwd)
        return self.user_or_pwd_error, rest_error

    def input_error_password_and_correct_username(self):
        """
        输入正确的用户名，错误密码
        :return:
        """
        rest_error = self.obj_login.input_username_password_and_username_error(self.username, '123456789x%')
        return self.user_or_pwd_error, rest_error

    def input_current_password_and_username(self):
        """
        输入正确的用户名和密码登录成功
        """
        rest_success = self.obj_login.input_username_password_and_username(self.username, self.pwd)
        return self.login_success, rest_success

    def quit_browser(self):
        """
        关闭浏览器
        :return:
        """
        self.obj_login.quit_browser()


if __name__ == '__main__':
    LoginHandle().input_current_password_and_username()
